/**
 * scene基类;
 * 注意子类名称必须与Scenes里注册的名称相同;
 */
import {global} from '../Main';
export abstract class BaseScene {
    public scene: BABYLON.Scene;
    public GUI3DManager: BABYLON.GUI.GUI3DManager;
    public sceneType: SCENE;

    constructor() {
        this.sceneType = SCENE[this.constructor.name];
        this.scene = new BABYLON.Scene(global.engine);
        this.GUI3DManager = new BABYLON.GUI.GUI3DManager(this.scene);
        this.iniScene();

        global.addPrestrainedScene(this, this.sceneType);
    }

    /**
     * 使用gui3d对点击事件进行响应;
     * @param mesh 
     * @param callBack 回调函数，要执行的代码放在这里
     * @param animation 是否启用按钮动画
     */
    public clickToDo(mesh: BABYLON.Mesh, callBack: ()=>void, animation: boolean = false){
        var btn3D = new BABYLON.GUI.MeshButton3D(mesh);
        if(!animation){   //禁用3d button的点击动画
            btn3D.pointerEnterAnimation = ()=>{
    
            };
            btn3D.pointerOutAnimation = ()=>{
        
            };
            btn3D.pointerUpAnimation = ()=>{
        
            };
            btn3D.pointerDownAnimation = ()=>{
        
            };
        }
        btn3D.onPointerClickObservable.add(callBack);
        this.GUI3DManager.addControl(btn3D);
    }

    /**
     * 使用gui3d对点击事件进行响应, 切换场景;
     * @param mesh 
     * @param renderScene 
     */
    public clickToRender3D(mesh: BABYLON.Mesh, renderScene: SCENE, animation: boolean = false){
        var render = () => {
            this.askForRender(renderScene);
        };
        this.clickToDo(mesh, render, animation);
    }

    /**
     * 请求切换场景;
     * @param renderScene 
     */
    public askForRender(renderScene: SCENE){
        this.GUI3DManager.utilityLayer.shouldRender = false;    //关闭本场景的gui
        global.scenesInitialed[renderScene].GUI3DManager.utilityLayer.shouldRender = true;  //开启要渲染场景的gui
        global.askForRender(renderScene);
    }

    /**
     * 覆写此方法来创建一个场景;
     *  {
        var engine = global.engine;
        var canvas = global.canvas;
        var scene = this.scene;
        //以下将playground的代码粘贴即可
        var scene = new BABYLON.Scene(engine);

        return scene;
    }
     * @returns
     */
    abstract iniScene(): void;
}